import { BroadCastCall } from "../broadCast/BroadCastCall";
import { MessageBlock } from "../../../../Framework/MQ/MessageBlock";
import { EGateCommand } from "../../../../Message/Command/EGateCommand";
import { SFriendRecordMsg } from "../../../../Message/Game/SFriendRecordMsg";
import { EUpdateType } from "../../../../Message/Public/EUpdateType";
import { Cache } from "../../cache/Cache";
import { NetDispatcher } from "../../../mvc/core/NetDispatcher";
import { ServerCommand } from "../../mvc/ServerCommand";
import { EFriendFlag } from "../../../../Message/Game/EFriendFlag";
import { SSeqAttributeUpdate } from "../../../../Message/Public/SSeqAttributeUpdate";
import { EEntityAttribute } from "../../../../Message/Public/EEntityAttribute";
//class FriendUpdateCommand
    
    export  class FriendUpdateCommand extends BroadCastCall
    {
        constructor(arg1: Object)
        {
            super(arg1);
            return;
        }

        public /* override */ call(arg1: MessageBlock): void
        {
            var loc1=null;
            var loc2=null;
            var loc3=0;
            var loc4=null;
            var loc5=null;
            var loc6=0;
            var loc7=null;
            var loc8=0;
            var loc9=0;
            var loc10=0;
            var loc11=0;
            var loc12=0;
            var loc13=0;
            var loc14=0;
            super.call(arg1);
            var loc15=arg1.messageHead.command;
            switch (loc15) 
            {
                case EGateCommand._ECmdGateFriendRecord:
                {
                    loc1 = arg1.messageBase as SFriendRecordMsg;
                    loc15 = loc1.type;
                    switch (loc15) 
                    {
                        case EUpdateType._EUpdateTypeAdd:
                        {
                            Cache.instance.friend.addFriend(loc1.friendRecord);
                            NetDispatcher.dispatchCmd(ServerCommand.FriendAdd, loc1);
                            loc4 = "";
                            if (loc1.friendRecord.flag == EFriendFlag._EFriendFlagFriend) 
                            {
                                loc4 = "添加好友成功";
                            }
                            if (loc4 == "") 
                            {
                                return;
                            }
                            break;
                        }
                        case EUpdateType._EUpdateTypeDel:
                        {
                            Cache.instance.friend.removeFriendByName(loc1.friendRecord.friendPlayer.name, loc1.friendRecord.flag);
                            NetDispatcher.dispatchCmd(ServerCommand.FriendRemove, null);
                            break;
                        }
                        case EUpdateType._EUpdateTypeUpdate:
                        {
                            Cache.instance.friend.updateFriend(loc1.friendRecord);
                            NetDispatcher.dispatchCmd(ServerCommand.FriendUpdate, null);
                            break;
                        }
                    }
                    break;
                }
                case EGateCommand._ECmdGateFriendInfoUpdate:
                {
                    loc2 = arg1.messageBase as SSeqAttributeUpdate;
                    loc15 = 0;
                    var loc16=loc2.updates;
                    for(loc5 of loc16) 
                    {
                        if (loc5.attribute.value() == EEntityAttribute._EAttributeLevel) 
                        {
                            loc3 = loc5.value;
                            loc6 = int(loc5.valueStr);
                            Cache.instance.friend.updateLevelByPlayerId(loc3, loc6);
                        }
                        if (loc5.attribute.value() == EEntityAttribute._EAttributeName) 
                        {
                            loc3 = loc5.value;
                            loc7 = loc5.valueStr;
                            Cache.instance.friend.updateNameByPlayerId(loc3, loc7);
                        }
                        if (loc5.attribute.value() == EEntityAttribute._EAttributeFriendIntimate) 
                        {
                            loc3 = loc5.value;
                            loc8 = int(loc5.valueStr);
                            Cache.instance.friend.updateIntimateByPlayerId(loc3, loc8);
                        }
                        if (loc5.attribute.value() == EEntityAttribute._EAttributeVIPType) 
                        {
                            loc3 = loc5.value;
                            loc9 = int(loc5.valueStr);
                            Cache.instance.friend.updateVIPByPlayerId(loc3, loc9);
                        }
                        if (loc5.attribute.value() == EEntityAttribute._EAttributeCareer) 
                        {
                            loc3 = loc5.value;
                            loc10 = int(loc5.valueStr);
                            Cache.instance.friend.updateCareerByPlayerId(loc3, loc10);
                        }
                        if (loc5.attribute.value() == EEntityAttribute._EAttributeCareerEnable) 
                        {
                            loc3 = loc5.value;
                            loc11 = int(loc5.valueStr);
                            Cache.instance.friend.updateCareerEnableByPlayerId(loc3, loc11);
                        }
                        if (loc5.attribute.value() == EEntityAttribute._EAttributeSex) 
                        {
                            loc3 = loc5.value;
                            loc12 = int(loc5.valueStr);
                            Cache.instance.friend.updateSexByPlayerId(loc3, loc12);
                        }
                        if (loc5.attribute.value() == EEntityAttribute._EAttributeCamp) 
                        {
                            loc3 = loc5.value;
                            loc13 = int(loc5.valueStr);
                            Cache.instance.friend.updateCampByPlayerId(loc3, loc13);
                        }
                        if (loc5.attribute.value() != EEntityAttribute._EAttributeAvatar) 
                        {
                            continue;
                        }
                        loc3 = loc5.value;
                        loc14 = int(loc5.valueStr);
                        Cache.instance.friend.updateAvatarByPlayerId(loc3, loc14);
                    }
                    NetDispatcher.dispatchCmd(ServerCommand.FriendAttributeUpdate, loc2);
                    break;
                }
            }
            return;
        }
    }
